package com.teapos.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {

	public static String md5(String inputStr) {
	    String md5Str = null;
		try {
			md5Str = inputStr;
			if(inputStr != null) {
			    MessageDigest md = MessageDigest.getInstance("MD5");
			    md.update(inputStr.getBytes());
			    BigInteger hash = new BigInteger(1, md.digest());
			    md5Str = hash.toString(16);
			    if((md5Str.length() % 2) != 0) {
			        md5Str = "0" + md5Str;
			    }
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	    return md5Str;
	}
	
	public static void main(String[] args) {
		String s = "admin";
		try{
			System.out.println(md5(s));
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
